package com.tankgame;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: FENGYiMing
 * @Date: 2024/03/29/11:26
 * @Description: 坦克
 */
public class Tank {
    /**
     * 坦克的横坐标
     */
    private int x;
    /**
     * 坦克的纵坐标
     */
    private int y;
    private int speed = 1;

    private int direction;
    private boolean isLive = true;

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    private int movingDistance = (int) (Math.random() * 150 + 40);

    public int getMovingDistance() {
        return movingDistance;
    }

    public void setMovingDistance(int movingDistance) {
        this.movingDistance = movingDistance;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    /**
     * 向上移动
     */
    public void moveUp() {
        if (y > 0) {
            y -= speed;
            setMovingDistance((int) (Math.random() * 150 + 40));
        } else {
            setMovingDistance(1);
            setDirection((int) (Math.random() * 4 + 1));
        }
    }

    /**
     * 向右移动
     */
    public void moveRight() {
        if (x + 80 < 900) {
            x += speed;
            setMovingDistance((int) (Math.random() * 150 + 40));
        } else {
            setMovingDistance(1);
            setDirection((int) (Math.random() * 4 + 1));
        }
    }

    /**
     * 向下移动
     */
    public void moveDown() {
        if (y + 100 < 650) {
            y += speed;
            setMovingDistance((int) (Math.random() * 150 + 40));

        } else {
            setMovingDistance(1);
            setDirection((int) (Math.random() * 4 + 1));
        }
    }

    /**
     * 向左移动
     */
    public void moveLeft() {
        if (x > 0) {
            setMovingDistance((int) (Math.random() * 150 + 40));
            x -= speed;
        } else {
            setMovingDistance(1);
            setDirection((int) (Math.random() * 4 + 1));
        }
    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public Tank(int x, int y, int direction) {
        this.x = x;
        this.y = y;
        this.direction = direction;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
}
